@echo off
echo ================================
echo    Nginx 停止脚本
echo ================================

:: 检查nginx是否在运行
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
if "%ERRORLEVEL%"=="1" (
    echo nginx未在运行
    pause
    exit /b 0
)

echo 正在停止nginx...

:: 方法1: 优雅停止
set NGINX_DIR=C:\nginx
if exist "%NGINX_DIR%\nginx.exe" (
    cd /d "%NGINX_DIR%"
    nginx.exe -s quit
    timeout /t 3 >nul
)

:: 检查是否还在运行
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
if "%ERRORLEVEL%"=="0" (
    echo 优雅停止失败，强制停止...
    taskkill /F /IM nginx.exe
    timeout /t 1 >nul
)

:: 最终检查
tasklist /FI "IMAGENAME eq nginx.exe" 2>NUL | find /I /N "nginx.exe">NUL
if "%ERRORLEVEL%"=="1" (
    echo nginx已成功停止
) else (
    echo 警告: nginx可能仍在运行，请手动检查
)

pause
